Jakarta Bean Validation
後端開發 API 時, 常需要對 Request 欄位最條件檢核, Ex: Not NULL, 僅限數字, 長度限制... 等. 尤其若串接資料庫時, 欄位檢核更是必要的.
Node.js Express 開發常搭配 Express-Validator middleware 來簡化資料欄位基本驗證的 coding 瑣事, 查找 SpringBoot 是否也有類似的 middleware 時, 發現
Jakarta Bean Validation
這個更好用的套件.
Overview
Jakarta Bean Validation
Jakarta Bean Validation Constraints
Built-In Jakarta Bean Validation Constraints 都很實用. Ref: Introduction to Jakarta Bean Validation :: Jakarta EE Tutorial :: Jakarta EE Documentation.
Constraint | Description | Example |
| The value of the field or property must be false. |
|
| The value of the field or property must be true. |
|
| The value of the field or property must be a decimal value lower than or equal to the number in the value element. |
|
| The value of the field or property must be a decimal value greater than or equal to the number in the value element. |
|
| The value of the field or property must be a number within a specified range. The integer element specifies the maximum integral digits for the number, and the fraction element specifies the maximum fractional digits for the number. |
|
| The value of the field or property must be a valid email address. |
|
| The value of the field or property must be a date in the future. |
|
| The value of the field or property must be a date or time in present or future. |
|
| The value of the field or property must be an integer value lower than or equal to the number in the value element. |
|
| The value of the field or property must be an integer value greater than or equal to the number in the value element. |
|
| The value of the field or property must be a negative number. |
|
| The value of the field or property must be negative or zero. |
|
| The value of the field or property must contain at least one non-white space character. |
|
| The value of the field or property must not be empty. The length of the characters or array, and the size of a collection or map are evaluated. |
|
| The value of the field or property must not be null. |
|
| The value of the field or property must be null. |
|
| The value of the field or property must be a date in the past. |
|
| The value of the field or property must be a date or time in the past or present. |
|
| The value of the field or property must match the regular expression defined in the regexp element. |
|
| The value of the field or property must be a positive number. |
|
| The value of the field or property must be a positive number or zero. |
|
| The size of the field or property is evaluated and must match the specified boundaries. If the field or property is a String, the size of the string is evaluated. If the field or property is a Collection, the size of the Collection is evaluated. If the field or property is a Map, the size of the Map is evaluated. If the field or property is an array, the size of the array is evaluated. Use one of the optional max or min elements to specify the boundaries. |
|